<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>window对象的引用</title>
</head>
<body>
  <p>window对象的引用</p>
  <form>
    <p>
      <input type="button" id="creatWin" value="creat new window" />
      <input type="button" id="closeWin" value="close new window" />
    </p>
  </form>
</body>
<script type="text/javascript">
//事件绑定
function addEvent(elem,evtType,func) {
  if(elem.addEventListener) {
    elem.addEventListener(evtType,func,false);
  }else if (elem.attachEvent) {
    elem.attachEvent("on"+evtType,func);
  }else{
    elem["on"+evtType]=func;
  }
  }

//脚本正文
addEvent(window,"load",initialize);
function initialize() {
  var buttonCreat = document.getElementById('creatWin');
  var buttonClose = document.getElementById('closeWin');
  buttonCreat.onclick=makeNewwin;
  buttonClose.onclick=closeNewwin;
}
  var newWin;
  function makeNewwin() {
    newWin=window.open("","","height=300,width=400");
  }
  function closeNewwin(){
    if(newWin){
      newWin.close();
      newWin=null;
    }
  }

</script>
</html>
